package com.sl.algorithm;

/**
 * Created by lisulong on 2019/12/6.
 */
public class BubbleSort {
    /**
     * 冒泡排序
     *
     * @param array 待排序数组
     * 平均时间复杂度：O(n^2);最好情况：O(n);最坏情况：O(n^2);空间复杂度：O(1);排序方式：In-place
     * @return
     */
    public static int[] bubbleSort(int[] array) {
        if (array.length == 0)
            return array;
        for (int i = 0; i < array.length; i++)
            for (int j = 0; j < array.length - 1 - i; j++)
                if (array[j + 1] < array[j]) {
                    int temp = array[j + 1];
                    array[j + 1] = array[j];
                    array[j] = temp;
                }
        return array;
    }
}
